/*
 * @Author: wangmyng wangmyng@163.com
 * @Date: 2025-10-29 19:35:21
 * @LastEditors: wangmyng wangmyng@163.com
 * @LastEditTime: 2025-11-09 23:12:33
 */
import { get, post } from "@/utils/request";

export const getFilterRows = (worksheetId: string, filters?: any[], pageIndex?: number, pageSize?: number, options = {}) => {
  const requestData = {
    appKey: "692ae92ece83a4b7",
    sign: "ZTcxNjFkOTFmOGFmMTZjMmUwYzA0M2U5MzhiMTE2MjU3NjdlNGNmNjEwYjk4NDA3OTg0NDYzODBmMzIzYWU4YQ==",
    worksheetId: worksheetId,
    pageIndex: pageIndex || 0,
    pageSize: pageSize ?? (Number.isInteger(pageIndex) ? 50 : 50000),
    notGetTotal: "false",
    filters: filters || [],
    ...options,
  };

  return post("/hap/api/v2/open/worksheet/getFilterRows", requestData, {
    dynamicBaseURL: "",
    // dynamicBaseURL: 'https://dia.szssscri.com'
  });
};

export const testHapWrapCamera = () => {
  const requestData = {
    appKey: "692ae92ece83a4b7",
    sign: "ZTcxNjFkOTFmOGFmMTZjMmUwYzA0M2U5MzhiMTE2MjU3NjdlNGNmNjEwYjk4NDA3OTg0NDYzODBmMzIzYWU4YQ==",
    name: "111",
  };

  return post("/hap/api/workflow/hooks2/NjhmYjMxYjkxOGU4MzEyMWE3NDkzNTlh", requestData, {
    dynamicBaseURL: "",
    // dynamicBaseURL: 'https://dia.szssscri.com'
  });
};

//图层树
export const fetchLayerTreeData = async () => {
  const res = await getFilterRows("layerConfiguration", undefined, undefined, undefined, {
    sortId: 'index',
    isAsc: true,
  });
  return res.rows || [];
};

//今日警情
export const fetchCurrentWarningList = async (filters?: any[], pageIndex?: number, pageSize?: number) => {
  const res = await getFilterRows("incidentInformation", filters, pageIndex, pageSize);
  return { total: res.total, rows: res.rows || [] };
};

//隐患列表
export const fetchHiddenDangerList = async (filters?: any[], pageIndex?: number, pageSize?: number) => {
  const res = await getFilterRows("hazardReinspection", filters, pageIndex, pageSize);
  return { total: res.total, rows: res.rows || [] };
};


export const fetchCameraList = async (filters?: any[], pageIndex?: number, pageSize?: number) => {
  const res = await getFilterRows("sxtlb", filters, pageIndex, pageSize);
  return { total: res.total, list: res.rows || [] };
};